<!DOCTYPE html>
<html>
	<head>
		<style type="text/css">
		.cancel_btn
		{
		margin:10px 0px 5px 35px
		}
		.continue_btn
		{
		margin:10px 35px 5px 0px
		}
		.selection_btn
		{
		background-image: url("file:///android_res/drawable/dropdown_bg.png");
		}
		</style>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link rel="stylesheet" href="../css/styles.css" />
		<!-- <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css"> -->
		<link rel="stylesheet" href="../css/jquery.mobile-1.3.1.min.css">
		<link rel="stylesheet" href="file:///android_asset/css/in.css">
		<!--<link type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" rel="stylesheet" /> -->
		<link type="text/css" href="../css/jqm-datebox.min.css" rel="stylesheet" /> 
		<!-- Extra Codiqa features -->
		<link rel="stylesheet" href="codiqa.ext.css">
		<!-- jQuery and jQuery Mobile -->
		<script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
		<script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
		<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
		<!-- Extra Codiqa features -->
		<script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>
		<script src="file:///android_asset/js/login.js"></script>
		<script type="text/javascript" src="../js/jqm-datebox.core.min.js"></script>
		<script type="text/javascript" src="../js/jqm-datebox.mode.datebox.min.js"></script>
		<script type="text/javascript" src="../js/jquery.mobile.datebox.i18n.en_US.utf8.js"></script>
	</head>
	<body >
		<div class="ui-header ui-bar-b" align="center" data-theme="b" data-role="header" role="banner">
			<p style="padding:10px;">
			<font size="3"> Boulder Detail - Update </font></p>
			<img style="float:right;height:35px; margin:-37px 6px 0px 0px;width:50px;border-radius:10px;" src="../images/signout.png" onclick="signout()">
		</div>
		<!-- Header -->
			<div data-role="content" >
				<form id="myForm" method="POST">
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-area" name="select-area">
						  <option value="">Area</option>
						  </select>
					</div>	
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-grade" name="select-grade">
						  <option value="">Grade</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-color" name="select-color">
						  <option value="">Color</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <input name="routeName" id="routeName" style="text-align:center" placeholder="Problem Name"  type="text">
					</div>
					<div id="datePicker1">
						<input name="datePicker" id="datePicker" style="text-align:center"type="text" placeholder="Set Date" data-role="datebox" data-options='{"mode":"datebox", "useNewStyle":true}'/>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-type" name="select-type">
						  <option value="">Type</option> 
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-setter" name="select-setter">
						  <option value="">Setter</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-style" name="select-style">
						  <option value="">Style</option> 
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-location" name="select-location">
						  <option value="">Location</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select  id="select-status" name="select-status">
						  <option value="">Status</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-Forerunner" name="select-Forerunner">
						  <option value="">Forerunner </option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-Inspected" name="select-Inspected" >
						  <option value="">Inspected</option>
						  </select>
					</div>
					<div style="margin:5px 0px 0px 0px">
						  <select id="select-Strip" name="select-Strip" >
						  <option value="">Add To Strip List</option>
						  </select>
					</div>
					<!--<div>
						<center><input type="checkbox" style="margin:0px 0 0 -21px" height="45" width="100" id="check1" value="0" name="check1" onclick="checkBox()"/>
						 <div style="margin:0 0 0 -130px;font-family:Lucida Sans Unicode;">Add To Strip List</div></center>
					</div>-->
					<center><p><textarea placeholder="comment" id="comment" name="comment" style="width:100%;border:2px solid #000;"></textarea></p></center>
					<div>
						<a href="#" style="float:left;margin:0px 10px 0px 0px;"> <img src="../images/cancel.png" onclick="goBack()" width = "120" height="40"></a> 
						<a href="#" style="float:right;margin:0px 0px 0px 10px;"> <img src="../images/continue.png" onclick="sendDetails()" width = "120" height="40"></a>           
					</div> 
			</form>
			<div><p style="font-size:75pt;">&nbsp;</p></div>
		</div>				 
</body>
	<div style="background-image: url(../images/topbar.png); bottom:0;text-align:center;margin:0px 0px 0px 0px;" id="sample" class="ui-footer-fixed " > 
				<div style="margin:8px 0px -7px 17px;">
					<img  style="margin:0px -1px 13px -17px;" class="folder" src="../images/folder.png"  height="40" width="40" onclick="folder()">
					<img  style="margin:0px -1px 13px 19px;" class="folder" src="../images/settings.png" height="40" width="40" onclick="settings()">
					<img  style="margin:0px -1px 13px 19px;" class="" src="../images/home.png" height="40" width="40" onclick="home()">
					<img  style="margin:0px -1px 13px 19px;" class="folder" src="../images/boulder.png" height="40" width="40" onclick="boulder()">
					<img  style="margin:0px -1px 13px 19px;" class="folder" src="../images/route.png" height="40" width="40" onclick="route()">
				</div>
	</div>
</html>
	<script type="text/javascript" charset="utf-8" src="file:///android_asset/js/cordova.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	<script>
	function signout(){
		window.location='index_login.html';
	}
	function folder(){
		<!-- window.location='http://forerunnerpro.com/?nr=0'; -->
		navigator.app.loadUrl('http://forerunnerpro.com/?nr=0', { openExternal:true });
	}
	function settings(){
		window.location='settings.html';
	}
	function home(){
		window.location='option.html';
	}
	function boulder(){
		window.location='boulder_option.html';
	}
	function route(){
		window.location='route_option.html';
	}
	function goBack(){
		window.location='search_boulder.html';
	}
	var commentValue1='';var forerunnerValue1='';var locationValue1='';var styleValue1='';var setterValue1='';var typeValue1='';var dateValue1='';var routeNameValue1='';var colorValue1='';var gradeValue1='';var areaValue1='';var climbSystemValue='';
	var Area='';var grade=''; var colors='';var Type='';var SetterValue=''; var Style='';var Location='';var Forerunner='';var dateValue2='';var userIdValue='';var statusValue='';
	var id=window.localStorage["locationId"];var arr1 = [];var arr2 = []; var inspectedValue1='';
	var email=window.localStorage["username1"];var stripValue1='';
	var token1=encodeURIComponent(window.localStorage["token"]);
	document.addEventListener("deviceready", updateRopeRoute, false);
	function updateRopeRoute(){
			//area options
			$('#select-area').parent().find('.ui-btn-text').text(window.localStorage["areaName"]);
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/locations/'+id+'/areas?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){ 
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
						Area+="<option value="+value.areaId+">"+value.areaName+"</option>";
						});	
					$("#select-area").append(Area);						
					}
				}
			});
			//get climb system id by location group id
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/climbsystemsbygroup/'+window.localStorage["GroupId"]+'/?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){
						if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
							window.localStorage["climbSystemId"] = data.data.climbSystemId;
						 });				
					}
				}
			});		
			// grade options
			$('#select-grade').parent().find('.ui-btn-text').text(window.localStorage["gradeName"]);
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/gradesbyclimbsystem/'+window.localStorage["climbSystemId"]+'/?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){	
						$('#select-grade').append($("<option></option>").attr("value",value.gradeId).text(value.gradeName));
						 });				
					}else if(data.errorCode=="100"){
						navigator.notification.alert("Please Sign In");
						window.location='index_login.html';
						return false;
					}
				}
			});	
			//colors options
			$('#select-color').parent().find('.ui-btn-text').text(window.localStorage["colorName"]);
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/colorsbylocationgrp/'+window.localStorage["GroupId"]+'/?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){	
						colors+="<option value="+value.colorId+">"+value.colorName+"</option>";
						});	
					$("#select-color").append(colors);	
					}
				}
			});
			//routeName
			if(window.localStorage["routeName"]!="undefined"){
			$("#routeName").val(window.localStorage["routeName"]);}
			//datePicker
			$("#datePicker").val(window.localStorage["modifiedDate"]);
			//type options
			$('#select-type').parent().find('.ui-btn-text').text(window.localStorage["routeTypeName"]);
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/routetypesbyroute/boulder?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){	
						Type+="<option value="+value.routeTypeId+">"+value.routeTypeName+"</option>";
						});	
						$("#select-type").append(Type);			
					}
				}
			});
			// setter options
			$.ajax({
					type: "GET",
					url: window.localStorage["url"]+'/getuserprofile/'+window.localStorage["userId"]+'?token='+token1,
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
							if(key=="user"){
								$('#select-setter').parent().find('.ui-btn-text').text(value.firstName+' '+value.lastName);
							}
						});	
					}
				}
			});	
			$.ajax({
				type: "GET",
				url: window.localStorage["url"]+'/getsettersforlocationgrp/'+window.localStorage["GroupId"]+'?token='+token1,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function(data){ 
					if(data.status == "SUCCESS"){
					$.each(data.data, function(key,value){	
							SetterValue+="<option value="+value.userid+">"+value.firstName+" "+value.lastName+"</option>";
							});
						$("#select-setter").append(SetterValue);			
					}
				}
			});	
			//climbStyleName options	
			$('#select-style').parent().find('.ui-btn-text').text(window.localStorage["climbStyleName"]);
			$.ajax({
					type: "GET",
					url: window.localStorage["url"]+'/climbstyles?token='+token1,
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
						Style+="<option value="+value.climbStyleId+">"+value.climbStyleName+"</option>";
						});
					$("#select-style").append(Style);	
					}
				}	
			});	
			//location options
			$('#select-location').parent().find('.ui-btn-text').text(window.localStorage["locationName"]);
			$.ajax({
					type: "GET",
					url: window.localStorage["url"]+'/getlocationsforuser?userName='+email+'&token='+token1,
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data){
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){	
						Location+="<option value="+value.locationId+">"+value.name+"</option>";
						});	
						$("#select-location").append(Location);			
					}else if(data.errorCode=="100"){
						navigator.notification.alert("Please Sign In");
						window.location='index_login.html';
						return false;
					}
				}
			});
			//status
			if(window.localStorage["status"]==1){
			$('#select-status').parent().find('.ui-btn-text').text("Active");
			$("#select-status").append("<option value='1'>Active</option>");
			$("#select-status").append("<option value='2'>InActive</option>");
			}else{
			$('#select-status').parent().find('.ui-btn-text').text("InActive");
			$("#select-status").append("<option value='1'>Active</option>");
			$("#select-status").append("<option value='2'>InActive</option>");
			}
			// create Frunner options
			if(window.localStorage["forerunnerFirstName"]!="undefined"){
			$('#select-Forerunner').parent().find('.ui-btn-text').text(window.localStorage["forerunnerFirstName"]+" "+window.localStorage["forerunnerLastName"]);
			$.ajax({
					type: "GET",
					url: window.localStorage["url"]+'/gettesters/'+window.localStorage["locationGroupId"]+'?token='+token1,
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data){ 
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
						Forerunner+="<option value="+value.userid+">"+value.firstName+" "+value.lastName+"</option>";
						});	
					$("#select-Forerunner").append(Forerunner);	
					}
				}
			});
			}else{
			$('#select-Forerunner').parent().find('.ui-btn-text').text("Forerunner");
			$("#select-Forerunner option[value='0']").remove();
			$.ajax({
					type: "GET",
					url: window.localStorage["url"]+'/gettesters/'+window.localStorage["locationGroupId"]+'?token='+token1,
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data){ 
					if(data.status == "SUCCESS"){
						$.each(data.data, function(key,value){
						Forerunner+="<option value="+value.userid+">"+value.firstName+" "+value.lastName+"</option>";
						});	
					$("#select-Forerunner").append(Forerunner);	
					}
				}
			});}
			//Inspected
			if(window.localStorage["inspected"]=="true"){
			$('#select-Inspected').parent().find('.ui-btn-text').text("TRUE");
			$("#select-Inspected").append("<option value='true'>True</option>");
			$("#select-Inspected").append("<option value='false'>False</option>");
			}else{
			$('#select-Inspected').parent().find('.ui-btn-text').text("False");
			$("#select-Inspected").append("<option value='true'>True</option>");
			$("#select-Inspected").append("<option value='false'>False</option>");
			}
			//AddToStripListStrip
			if(window.localStorage["addToStripList"]=="true"){
			$('#select-Strip').parent().find('.ui-btn-text').text("YES");
			$("#select-Strip").append("<option value='true'>YES</option>");
			$("#select-Strip").append("<option value='false'>NO</option>");
			}else{
			$('#select-Strip').parent().find('.ui-btn-text').text("NO");
			$("#select-Strip").append("<option value='true'>YES</option>");
			$("#select-Strip").append("<option value='false'>NO</option>");
			}
			//comment
			if(window.localStorage["comment"]!='undefined'){
			$('#comment').val(window.localStorage["comment"]);}	
	}
	function sendDetails(){
		var areaValue=$('#select-area').val();
		var gradeValue=$("#select-grade").val();
		var colorValue=$("#select-color").val();
		var typeValue=$("#select-type").val();
		var routeNameValue=$("#routeName").val();
		var dateValue=$("#datePicker").val();			
		var setterValue1=$("#select-setter").val();
		var styleValue=$("#select-style").val();
		var locationValue=$("#select-location").val();
		var statusValue=$("#select-status").val();
		var forerunnerValue=$("#select-Forerunner").val();
		var inspectedValue=$("#select-Inspected").val();
		var stripValue=$("#select-Strip").val();	
		var	commentValue=$("#comment").val();
			if(areaValue==""){
				areaValue1="'areaId':'"+window.localStorage["areaId"]+"',";
				}else{
				areaValue1="'areaId':'"+areaValue+"',";}
			if(gradeValue==""){
				gradeValue1="'grade':'"+window.localStorage["gradeId"]+"',";
				}else{
				gradeValue1="'grade':'"+gradeValue+"',";}
			if(colorValue==""){
				colorValue1="'color':'"+window.localStorage["colorId"]+"',";
				}else{
				colorValue1="'color':'"+colorValue+"',";}
			if(routeNameValue==""){
				routeNameValue1="'routeName':'"+window.localStorage["routeName"]+"',";
				}else{
				routeNameValue1="'routeName':'"+routeNameValue+"',";}
			var today = new Date();
			var dd = today.getDate();
			var mm = today.getMonth()+1; //January is 0!
			var yyyy = today.getFullYear();
			var fromDate=""+yyyy+"-"+mm+"-"+dd+"";
			var Pdate2=$("#datePicker").val();
			var array1 = Pdate2.split('/');
			var Pdate=""+array1[2]+"-"+array1[0]+"-"+array1[1]+"";
			if (Date.parse(fromDate) < Date.parse(Pdate)) {
				navigator.notification.alert("Please Select The Valid Date");
				return false;
				}
			if(typeValue==""){
				typeValue1="'routeType':'"+window.localStorage["routeTypeId"]+"',";
				}else{
				typeValue1="'routeType':'"+typeValue+"',";}
			if(setterValue1==""){
				setterValue="'userId':'"+window.localStorage["userId"]+"',";
				}else{
				setterValue="'userId':'"+setterValue1+"',";}
			if(styleValue==""){
				styleValue1="'climbStyle':'"+window.localStorage["climbStyleId"]+"',";
				}else{
				styleValue1="'climbStyle':'"+styleValue+"',";}
			if(locationValue==""){
				locationValue1="'locationId':'"+window.localStorage["locationId"]+"',";
				}else{
				locationValue1="'locationId':'"+locationValue+"',";}
			if(statusValue==""){
				statusValue="'status':'"+window.localStorage["status"]+"',";
				}else if(statusValue=="1"){
				statusValue="'status':'1',";
				}else{
				statusValue="'status':'2',";}	
			if(forerunnerValue==""){
				Forerunner='';
				}else{
				Forerunner="'testerId':'"+forerunnerValue+"',";}
			if(inspectedValue==""){
				inspectedValue1="'inspected':'"+window.localStorage["inspected"]+"',";
				}else{
				inspectedValue1="'inspected':'"+inspectedValue+"',";}
			if(stripValue==""){
				stripValue1="'addToStripList':'"+window.localStorage["addToStripList"]+"',";
				}else{
				stripValue1="'addToStripList':'"+stripValue+"',";}
			if(commentValue==""){
				commentValue1="'comment':'"+commentValue+"',";
				}else{
				commentValue1="'comment':'"+commentValue+"',";}
			climbSystemValue="'climbSystem':'"+window.localStorage["climbSystemId"]+"',";
			
			var array2=window.localStorage["createDate"].split('/');
			var Cdate=""+array2[2]+"-"+array2[0]+"-"+array2[1]+"";
			
			dateValue1="'modifyDate':'"+fromDate+"',";
			dateValue2="'createDate':'"+Cdate+"',";
			
			var totalValue="{"+routeNameValue1+typeValue1+areaValue1+dateValue2+dateValue1+colorValue1+climbSystemValue+styleValue1+gradeValue1+setterValue+locationValue1+commentValue1+statusValue+Forerunner+inspectedValue1+stripValue1;
			totalValue = totalValue.replace(/'/g, '"');
			var strlen=totalValue.length;
			totalValue=totalValue.slice(0,strlen-1);
			totalValue+="}";
			window.localStorage["totalValue"]=totalValue;
			//navigator.notification.alert(window.localStorage["totalValue"]);
			$.ajax({
				type: "POST",
				url: window.localStorage["url"]+'/routes/'+window.localStorage["routeId"]+'?token='+token1,
				contentType: "application/json; charset=utf-8",
				data:window.localStorage["totalValue"],
				success: function(data){
					if(data.status == "SUCCESS"){
						navigator.notification.alert("The Route Database Has Been Updated");
						window.location='boulder_option.html';					
					}else if(data.errorCode=="100"){
						navigator.notification.alert("Please Sign In");
						window.location='index_login.html';
						return false;
					}				
				}			 	
			});
	}
	
	</script>
